/*
#define ATLAS_UART_REGS_BASE    0xbf000900
#define PORT(offset)    (ATLAS_UART_REGS_BASE + ((offset) << 3))

#void bsp_uart_putchar(char_t ch)
#if ( 0xbf000900 + (UART_LSR << 3) and 0x20 )
#else loop

#char_t bsp_uart_getchar(void)
#if (0xbf000900 + (UART_LSR << 3) and 0x01)
#else loop

#define UART_LSR                  5    In:  Line Status Register 
#define UART_LSR_THRE             0x20 Transmit-hold-register empty
#define UART_LSR_DR               0x01 Receiver data ready 
#define UART_RX                   0    In:  Receive buffer 
#define UART_TX                   0    Out: Transmit buffer 
*/

   .section   .text
   .text
   .align 2
   .global    getchar
   .global    putchar

/*
   32 bit access                          UART
   -------------------------------------------
   0xbf000900 => data_tx;
   0xbf000900 => data_rx;
   0xbf000928 => status
                 bit31:tx_is_ready
                 bit01:rx_isready
 */


uart_base=0xbf000900
uart_tx_data=0x00         
uart_rx_data=0x00
uart_status=0x28 # (5 << 3)
uart_tx_is_ready=0x20     
uart_rx_is_ready=0x01  


# get a character in $2
# uses $8,$9

getchar:	
        la      $8,uart_base
        nop
getchar0:	
        nop
        nop
        nop
        nop
        lw      $9,uart_status($8)
        andi    $9,uart_rx_is_ready
	nop

                /* Branch to address if the variable = 0 */
        beq     $9,$0,getchar0
        nop
        lw      $2,uart_rx_data($8)	    
	nop

        andi    $2,0xff  # clean dirty, it is a byte

	j	$31
	nop

# put a character in $4
# uses $8,$12

putchar:	
        la      $8,uart_base
        nop
putchar0:	
        andi    $4,0xff
	nop
        nop
        nop
        nop
        lw      $12,uart_status($8)
        andi    $12,uart_tx_is_ready
	nop
                /* Branch to address if the variable = 0 */
        beq     $12,$0,putchar0
	nop

	sw	$4,uart_tx_data($8)
        nop

	j	$31
	nop

